// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]
#![no_implicit_prelude]
extern crate async_trait;
extern crate bytes;
extern crate gax;
extern crate gaxi;
extern crate iam_v1;
extern crate lazy_static;
extern crate reqwest;
extern crate serde;
extern crate serde_json;
extern crate serde_with;
extern crate std;
extern crate tracing;
extern crate wkt;

mod debug;
mod deserialize;
mod serialize;

/// Request message for the CreateDataPolicy method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct CreateDataPolicyRequest {
    /// Required. Resource name of the project that the data policy will belong to.
    /// The format is `projects/{project_number}/locations/{location_id}`.
    pub parent: std::string::String,

    /// Required. User-assigned (human readable) ID of the data policy that needs
    /// to be unique within a project. Used as {data_policy_id} in part of the
    /// resource name.
    pub data_policy_id: std::string::String,

    /// Required. The data policy to create. The `name` field does not need to be
    /// provided for the data policy creation.
    pub data_policy: std::option::Option<crate::model::DataPolicy>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl CreateDataPolicyRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [parent][crate::model::CreateDataPolicyRequest::parent].
    pub fn set_parent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.parent = v.into();
        self
    }

    /// Sets the value of [data_policy_id][crate::model::CreateDataPolicyRequest::data_policy_id].
    pub fn set_data_policy_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.data_policy_id = v.into();
        self
    }

    /// Sets the value of [data_policy][crate::model::CreateDataPolicyRequest::data_policy].
    pub fn set_data_policy<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::DataPolicy>,
    {
        self.data_policy = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [data_policy][crate::model::CreateDataPolicyRequest::data_policy].
    pub fn set_or_clear_data_policy<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::DataPolicy>,
    {
        self.data_policy = v.map(|x| x.into());
        self
    }
}

impl wkt::message::Message for CreateDataPolicyRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.CreateDataPolicyRequest"
    }
}

/// Request message for the UpdateDataPolicy method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct UpdateDataPolicyRequest {
    /// Required. Update the data policy's metadata.
    ///
    /// The target data policy is determined by the `name` field.
    /// Other fields are updated to the specified values based on the field masks.
    pub data_policy: std::option::Option<crate::model::DataPolicy>,

    /// Optional. The update mask applies to the resource. For the `FieldMask`
    /// definition, see
    /// <https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask>
    /// If not set, defaults to all of the fields that are allowed to update.
    ///
    /// Updates to the `name` and `dataPolicyId` fields are not allowed.
    pub update_mask: std::option::Option<wkt::FieldMask>,

    /// Optional. If set to true, and the data policy is not found, a new data
    /// policy will be created. In this situation, update_mask is ignored.
    pub allow_missing: bool,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl UpdateDataPolicyRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [data_policy][crate::model::UpdateDataPolicyRequest::data_policy].
    pub fn set_data_policy<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<crate::model::DataPolicy>,
    {
        self.data_policy = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [data_policy][crate::model::UpdateDataPolicyRequest::data_policy].
    pub fn set_or_clear_data_policy<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<crate::model::DataPolicy>,
    {
        self.data_policy = v.map(|x| x.into());
        self
    }

    /// Sets the value of [update_mask][crate::model::UpdateDataPolicyRequest::update_mask].
    pub fn set_update_mask<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::FieldMask>,
    {
        self.update_mask = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [update_mask][crate::model::UpdateDataPolicyRequest::update_mask].
    pub fn set_or_clear_update_mask<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::FieldMask>,
    {
        self.update_mask = v.map(|x| x.into());
        self
    }

    /// Sets the value of [allow_missing][crate::model::UpdateDataPolicyRequest::allow_missing].
    pub fn set_allow_missing<T: std::convert::Into<bool>>(mut self, v: T) -> Self {
        self.allow_missing = v.into();
        self
    }
}

impl wkt::message::Message for UpdateDataPolicyRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.UpdateDataPolicyRequest"
    }
}

/// Request message for the AddGrantees method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct AddGranteesRequest {
    /// Required. Resource name of this data policy, in the format of
    /// `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}`.
    pub data_policy: std::string::String,

    /// Required. IAM principal that should be granted Fine Grained Access to the
    /// underlying data goverened by the data policy. The target data policy is
    /// determined by the `data_policy` field.
    ///
    /// Uses the [IAM V2 principal
    /// syntax](https://cloud.google.com/iam/docs/principal-identifiers#v2).
    /// Supported principal types:
    ///
    /// * User
    /// * Group
    /// * Service account
    pub grantees: std::vec::Vec<std::string::String>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl AddGranteesRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [data_policy][crate::model::AddGranteesRequest::data_policy].
    pub fn set_data_policy<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.data_policy = v.into();
        self
    }

    /// Sets the value of [grantees][crate::model::AddGranteesRequest::grantees].
    pub fn set_grantees<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.grantees = v.into_iter().map(|i| i.into()).collect();
        self
    }
}

impl wkt::message::Message for AddGranteesRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.AddGranteesRequest"
    }
}

/// Request message for the RemoveGrantees method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct RemoveGranteesRequest {
    /// Required. Resource name of this data policy, in the format of
    /// `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}`.
    pub data_policy: std::string::String,

    /// Required. IAM principal that should be revoked from Fine Grained Access to
    /// the underlying data goverened by the data policy. The target data policy is
    /// determined by the `data_policy` field.
    ///
    /// Uses the [IAM V2 principal
    /// syntax](https://cloud.google.com/iam/docs/principal-identifiers#v2).
    /// Supported principal types:
    ///
    /// * User
    /// * Group
    /// * Service account
    pub grantees: std::vec::Vec<std::string::String>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl RemoveGranteesRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [data_policy][crate::model::RemoveGranteesRequest::data_policy].
    pub fn set_data_policy<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.data_policy = v.into();
        self
    }

    /// Sets the value of [grantees][crate::model::RemoveGranteesRequest::grantees].
    pub fn set_grantees<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.grantees = v.into_iter().map(|i| i.into()).collect();
        self
    }
}

impl wkt::message::Message for RemoveGranteesRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.RemoveGranteesRequest"
    }
}

/// Request message for the DeleteDataPolicy method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct DeleteDataPolicyRequest {
    /// Required. Resource name of the data policy to delete. Format is
    /// `projects/{project_number}/locations/{location_id}/dataPolicies/{id}`.
    pub name: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl DeleteDataPolicyRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::DeleteDataPolicyRequest::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }
}

impl wkt::message::Message for DeleteDataPolicyRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.DeleteDataPolicyRequest"
    }
}

/// Request message for the GetDataPolicy method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct GetDataPolicyRequest {
    /// Required. Resource name of the requested data policy. Format is
    /// `projects/{project_number}/locations/{location_id}/dataPolicies/{id}`.
    pub name: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl GetDataPolicyRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::GetDataPolicyRequest::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }
}

impl wkt::message::Message for GetDataPolicyRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.GetDataPolicyRequest"
    }
}

/// Request message for the ListDataPolicies method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct ListDataPoliciesRequest {
    /// Required. Resource name of the project for which to list data policies.
    /// Format is `projects/{project_number}/locations/{location_id}`.
    pub parent: std::string::String,

    /// Optional. The maximum number of data policies to return. Must be a value
    /// between 1 and 1000. If not set, defaults to 50.
    pub page_size: i32,

    /// Optional. The `nextPageToken` value returned from a previous list request,
    /// if any. If not set, defaults to an empty string.
    pub page_token: std::string::String,

    /// Optional. Filters the data policies by policy tags that they
    /// are associated with. Currently filter only supports
    /// "policy_tag" based filtering and OR based predicates. Sample
    /// filter can be "policy_tag:
    /// projects/1/locations/us/taxonomies/2/policyTags/3".
    /// You may also use wildcard such as "policy_tag:
    /// projects/1/locations/us/taxonomies/2*". Please note that OR predicates
    /// cannot be used with wildcard filters.
    pub filter: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl ListDataPoliciesRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [parent][crate::model::ListDataPoliciesRequest::parent].
    pub fn set_parent<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.parent = v.into();
        self
    }

    /// Sets the value of [page_size][crate::model::ListDataPoliciesRequest::page_size].
    pub fn set_page_size<T: std::convert::Into<i32>>(mut self, v: T) -> Self {
        self.page_size = v.into();
        self
    }

    /// Sets the value of [page_token][crate::model::ListDataPoliciesRequest::page_token].
    pub fn set_page_token<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.page_token = v.into();
        self
    }

    /// Sets the value of [filter][crate::model::ListDataPoliciesRequest::filter].
    pub fn set_filter<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.filter = v.into();
        self
    }
}

impl wkt::message::Message for ListDataPoliciesRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.ListDataPoliciesRequest"
    }
}

/// Response message for the ListDataPolicies method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct ListDataPoliciesResponse {
    /// Data policies that belong to the requested project.
    pub data_policies: std::vec::Vec<crate::model::DataPolicy>,

    /// Token used to retrieve the next page of results, or empty if there are no
    /// more results.
    pub next_page_token: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl ListDataPoliciesResponse {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [data_policies][crate::model::ListDataPoliciesResponse::data_policies].
    pub fn set_data_policies<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<crate::model::DataPolicy>,
    {
        use std::iter::Iterator;
        self.data_policies = v.into_iter().map(|i| i.into()).collect();
        self
    }

    /// Sets the value of [next_page_token][crate::model::ListDataPoliciesResponse::next_page_token].
    pub fn set_next_page_token<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.next_page_token = v.into();
        self
    }
}

impl wkt::message::Message for ListDataPoliciesResponse {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.ListDataPoliciesResponse"
    }
}

#[doc(hidden)]
impl gax::paginator::internal::PageableResponse for ListDataPoliciesResponse {
    type PageItem = crate::model::DataPolicy;

    fn items(self) -> std::vec::Vec<Self::PageItem> {
        self.data_policies
    }

    fn next_page_token(&self) -> std::string::String {
        use std::clone::Clone;
        self.next_page_token.clone()
    }
}

/// Represents the label-policy binding.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct DataPolicy {
    /// Identifier. Resource name of this data policy, in the format of
    /// `projects/{project_number}/locations/{location_id}/dataPolicies/{data_policy_id}`.
    pub name: std::string::String,

    /// Output only. User-assigned (human readable) ID of the data policy that
    /// needs to be unique within a project. Used as {data_policy_id} in part of
    /// the resource name.
    pub data_policy_id: std::string::String,

    /// The etag for this Data Policy.
    /// This field is used for UpdateDataPolicy calls. If Data Policy exists, this
    /// field is required and must match the server's etag. It will also be
    /// populated in the response of GetDataPolicy, CreateDataPolicy, and
    /// UpdateDataPolicy calls.
    pub etag: std::option::Option<std::string::String>,

    /// Required. Type of data policy.
    pub data_policy_type: crate::model::data_policy::DataPolicyType,

    /// Output only. Policy tag resource name, in the format of
    /// `projects/{project_number}/locations/{location_id}/taxonomies/{taxonomy_id}/policyTags/{policyTag_id}`.
    /// policy_tag is supported only for V1 data policies.
    pub policy_tag: std::string::String,

    /// Optional. The list of IAM principals that have Fine Grained Access to the
    /// underlying data goverened by this data policy.
    ///
    /// Uses the [IAM V2 principal
    /// syntax](https://cloud.google.com/iam/docs/principal-identifiers#v2) Only
    /// supports principal types users, groups, serviceaccounts, cloudidentity.
    /// This field is supported in V2 Data Policy only. In case of V1 data policies
    /// (i.e. verion = 1 and policy_tag is set), this field is not populated.
    pub grantees: std::vec::Vec<std::string::String>,

    /// Output only. The version of the Data Policy resource.
    pub version: crate::model::data_policy::Version,

    /// The policy that is bound to this data policy.
    pub policy: std::option::Option<crate::model::data_policy::Policy>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl DataPolicy {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [name][crate::model::DataPolicy::name].
    pub fn set_name<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.name = v.into();
        self
    }

    /// Sets the value of [data_policy_id][crate::model::DataPolicy::data_policy_id].
    pub fn set_data_policy_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.data_policy_id = v.into();
        self
    }

    /// Sets the value of [etag][crate::model::DataPolicy::etag].
    pub fn set_etag<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<std::string::String>,
    {
        self.etag = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [etag][crate::model::DataPolicy::etag].
    pub fn set_or_clear_etag<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<std::string::String>,
    {
        self.etag = v.map(|x| x.into());
        self
    }

    /// Sets the value of [data_policy_type][crate::model::DataPolicy::data_policy_type].
    pub fn set_data_policy_type<
        T: std::convert::Into<crate::model::data_policy::DataPolicyType>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.data_policy_type = v.into();
        self
    }

    /// Sets the value of [policy_tag][crate::model::DataPolicy::policy_tag].
    pub fn set_policy_tag<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.policy_tag = v.into();
        self
    }

    /// Sets the value of [grantees][crate::model::DataPolicy::grantees].
    pub fn set_grantees<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.grantees = v.into_iter().map(|i| i.into()).collect();
        self
    }

    /// Sets the value of [version][crate::model::DataPolicy::version].
    pub fn set_version<T: std::convert::Into<crate::model::data_policy::Version>>(
        mut self,
        v: T,
    ) -> Self {
        self.version = v.into();
        self
    }

    /// Sets the value of [policy][crate::model::DataPolicy::policy].
    ///
    /// Note that all the setters affecting `policy` are mutually
    /// exclusive.
    pub fn set_policy<
        T: std::convert::Into<std::option::Option<crate::model::data_policy::Policy>>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.policy = v.into();
        self
    }

    /// The value of [policy][crate::model::DataPolicy::policy]
    /// if it holds a `DataMaskingPolicy`, `None` if the field is not set or
    /// holds a different branch.
    pub fn data_masking_policy(
        &self,
    ) -> std::option::Option<&std::boxed::Box<crate::model::DataMaskingPolicy>> {
        #[allow(unreachable_patterns)]
        self.policy.as_ref().and_then(|v| match v {
            crate::model::data_policy::Policy::DataMaskingPolicy(v) => std::option::Option::Some(v),
            _ => std::option::Option::None,
        })
    }

    /// Sets the value of [policy][crate::model::DataPolicy::policy]
    /// to hold a `DataMaskingPolicy`.
    ///
    /// Note that all the setters affecting `policy` are
    /// mutually exclusive.
    pub fn set_data_masking_policy<
        T: std::convert::Into<std::boxed::Box<crate::model::DataMaskingPolicy>>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.policy = std::option::Option::Some(
            crate::model::data_policy::Policy::DataMaskingPolicy(v.into()),
        );
        self
    }
}

impl wkt::message::Message for DataPolicy {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.DataPolicy"
    }
}

/// Defines additional types related to [DataPolicy].
pub mod data_policy {
    #[allow(unused_imports)]
    use super::*;

    /// A list of supported data policy types.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum DataPolicyType {
        /// Default value for the data policy type. This should not be used.
        Unspecified,
        /// Used to create a data policy for data masking.
        DataMaskingPolicy,
        /// Used to create a data policy for raw data access.
        RawDataAccessPolicy,
        /// Used to create a data policy for column-level security, without data
        /// masking. This is deprecated in V2 api and only present to support GET and
        /// LIST operations for V1 data policies in V2 api.
        ColumnLevelSecurityPolicy,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [DataPolicyType::value] or
        /// [DataPolicyType::name].
        UnknownValue(data_policy_type::UnknownValue),
    }

    #[doc(hidden)]
    pub mod data_policy_type {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl DataPolicyType {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::DataMaskingPolicy => std::option::Option::Some(1),
                Self::RawDataAccessPolicy => std::option::Option::Some(2),
                Self::ColumnLevelSecurityPolicy => std::option::Option::Some(3),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("DATA_POLICY_TYPE_UNSPECIFIED"),
                Self::DataMaskingPolicy => std::option::Option::Some("DATA_MASKING_POLICY"),
                Self::RawDataAccessPolicy => std::option::Option::Some("RAW_DATA_ACCESS_POLICY"),
                Self::ColumnLevelSecurityPolicy => {
                    std::option::Option::Some("COLUMN_LEVEL_SECURITY_POLICY")
                }
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for DataPolicyType {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for DataPolicyType {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for DataPolicyType {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::DataMaskingPolicy,
                2 => Self::RawDataAccessPolicy,
                3 => Self::ColumnLevelSecurityPolicy,
                _ => Self::UnknownValue(data_policy_type::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for DataPolicyType {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "DATA_POLICY_TYPE_UNSPECIFIED" => Self::Unspecified,
                "DATA_MASKING_POLICY" => Self::DataMaskingPolicy,
                "RAW_DATA_ACCESS_POLICY" => Self::RawDataAccessPolicy,
                "COLUMN_LEVEL_SECURITY_POLICY" => Self::ColumnLevelSecurityPolicy,
                _ => Self::UnknownValue(data_policy_type::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for DataPolicyType {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::DataMaskingPolicy => serializer.serialize_i32(1),
                Self::RawDataAccessPolicy => serializer.serialize_i32(2),
                Self::ColumnLevelSecurityPolicy => serializer.serialize_i32(3),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for DataPolicyType {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<DataPolicyType>::new(
                ".google.cloud.bigquery.datapolicies.v2.DataPolicy.DataPolicyType",
            ))
        }
    }

    /// The supported versions for the Data Policy resource.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum Version {
        /// Default value for the data policy version. This should not be used.
        Unspecified,
        /// V1 data policy version. V1 Data Policies will be present in V2 List api
        /// response, but can not be created/updated/deleted from V2 api.
        V1,
        /// V2 data policy version.
        V2,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [Version::value] or
        /// [Version::name].
        UnknownValue(version::UnknownValue),
    }

    #[doc(hidden)]
    pub mod version {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl Version {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::V1 => std::option::Option::Some(1),
                Self::V2 => std::option::Option::Some(2),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("VERSION_UNSPECIFIED"),
                Self::V1 => std::option::Option::Some("V1"),
                Self::V2 => std::option::Option::Some("V2"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for Version {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for Version {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for Version {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::V1,
                2 => Self::V2,
                _ => Self::UnknownValue(version::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for Version {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "VERSION_UNSPECIFIED" => Self::Unspecified,
                "V1" => Self::V1,
                "V2" => Self::V2,
                _ => Self::UnknownValue(version::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for Version {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::V1 => serializer.serialize_i32(1),
                Self::V2 => serializer.serialize_i32(2),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for Version {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<Version>::new(
                ".google.cloud.bigquery.datapolicies.v2.DataPolicy.Version",
            ))
        }
    }

    /// The policy that is bound to this data policy.
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum Policy {
        /// Optional. The data masking policy that specifies the data masking rule to
        /// use. It must be set if the data policy type is DATA_MASKING_POLICY.
        DataMaskingPolicy(std::boxed::Box<crate::model::DataMaskingPolicy>),
    }
}

/// The policy used to specify data masking rule.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct DataMaskingPolicy {
    /// A masking expression to bind to the data masking rule.
    pub masking_expression:
        std::option::Option<crate::model::data_masking_policy::MaskingExpression>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl DataMaskingPolicy {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [masking_expression][crate::model::DataMaskingPolicy::masking_expression].
    ///
    /// Note that all the setters affecting `masking_expression` are mutually
    /// exclusive.
    pub fn set_masking_expression<
        T: std::convert::Into<
                std::option::Option<crate::model::data_masking_policy::MaskingExpression>,
            >,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.masking_expression = v.into();
        self
    }

    /// The value of [masking_expression][crate::model::DataMaskingPolicy::masking_expression]
    /// if it holds a `PredefinedExpression`, `None` if the field is not set or
    /// holds a different branch.
    pub fn predefined_expression(
        &self,
    ) -> std::option::Option<&crate::model::data_masking_policy::PredefinedExpression> {
        #[allow(unreachable_patterns)]
        self.masking_expression.as_ref().and_then(|v| match v {
            crate::model::data_masking_policy::MaskingExpression::PredefinedExpression(v) => {
                std::option::Option::Some(v)
            }
            _ => std::option::Option::None,
        })
    }

    /// Sets the value of [masking_expression][crate::model::DataMaskingPolicy::masking_expression]
    /// to hold a `PredefinedExpression`.
    ///
    /// Note that all the setters affecting `masking_expression` are
    /// mutually exclusive.
    pub fn set_predefined_expression<
        T: std::convert::Into<crate::model::data_masking_policy::PredefinedExpression>,
    >(
        mut self,
        v: T,
    ) -> Self {
        self.masking_expression = std::option::Option::Some(
            crate::model::data_masking_policy::MaskingExpression::PredefinedExpression(v.into()),
        );
        self
    }

    /// The value of [masking_expression][crate::model::DataMaskingPolicy::masking_expression]
    /// if it holds a `Routine`, `None` if the field is not set or
    /// holds a different branch.
    pub fn routine(&self) -> std::option::Option<&std::string::String> {
        #[allow(unreachable_patterns)]
        self.masking_expression.as_ref().and_then(|v| match v {
            crate::model::data_masking_policy::MaskingExpression::Routine(v) => {
                std::option::Option::Some(v)
            }
            _ => std::option::Option::None,
        })
    }

    /// Sets the value of [masking_expression][crate::model::DataMaskingPolicy::masking_expression]
    /// to hold a `Routine`.
    ///
    /// Note that all the setters affecting `masking_expression` are
    /// mutually exclusive.
    pub fn set_routine<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.masking_expression = std::option::Option::Some(
            crate::model::data_masking_policy::MaskingExpression::Routine(v.into()),
        );
        self
    }
}

impl wkt::message::Message for DataMaskingPolicy {
    fn typename() -> &'static str {
        "type.googleapis.com/google.cloud.bigquery.datapolicies.v2.DataMaskingPolicy"
    }
}

/// Defines additional types related to [DataMaskingPolicy].
pub mod data_masking_policy {
    #[allow(unused_imports)]
    use super::*;

    /// The available masking rules. Learn more here:
    /// <https://cloud.google.com/bigquery/docs/column-data-masking-intro#masking_options>.
    ///
    /// # Working with unknown values
    ///
    /// This enum is defined as `#[non_exhaustive]` because Google Cloud may add
    /// additional enum variants at any time. Adding new variants is not considered
    /// a breaking change. Applications should write their code in anticipation of:
    ///
    /// - New values appearing in future releases of the client library, **and**
    /// - New values received dynamically, without application changes.
    ///
    /// Please consult the [Working with enums] section in the user guide for some
    /// guidelines.
    ///
    /// [Working with enums]: https://google-cloud-rust.github.io/working_with_enums.html
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum PredefinedExpression {
        /// Default, unspecified predefined expression. No masking will take place
        /// since no expression is specified.
        Unspecified,
        /// Masking expression to replace data with SHA-256 hash.
        Sha256,
        /// Masking expression to replace data with NULLs.
        AlwaysNull,
        /// Masking expression to replace data with their default masking values.
        /// The default masking values for each type listed as below:
        ///
        /// * STRING: ""
        /// * BYTES: b''
        /// * INTEGER: 0
        /// * FLOAT: 0.0
        /// * NUMERIC: 0
        /// * BOOLEAN: FALSE
        /// * TIMESTAMP: 1970-01-01 00:00:00 UTC
        /// * DATE: 1970-01-01
        /// * TIME: 00:00:00
        /// * DATETIME: 1970-01-01T00:00:00
        /// * GEOGRAPHY: POINT(0 0)
        /// * BIGNUMERIC: 0
        /// * ARRAY: []
        /// * STRUCT: NOT_APPLICABLE
        /// * JSON: NULL
        DefaultMaskingValue,
        /// Masking expression shows the last four characters of text.
        /// The masking behavior is as follows:
        ///
        /// * If text length > 4 characters: Replace text with XXXXX, append last
        ///   four characters of original text.
        /// * If text length <= 4 characters: Apply SHA-256 hash.
        LastFourCharacters,
        /// Masking expression shows the first four characters of text.
        /// The masking behavior is as follows:
        ///
        /// * If text length > 4 characters: Replace text with XXXXX, prepend first
        ///   four characters of original text.
        /// * If text length <= 4 characters: Apply SHA-256 hash.
        FirstFourCharacters,
        /// Masking expression for email addresses.
        /// The masking behavior is as follows:
        ///
        /// * Syntax-valid email address: Replace username with XXXXX. For example,
        ///   cloudysanfrancisco@gmail.com becomes XXXXX@gmail.com.
        /// * Syntax-invalid email address: Apply SHA-256 hash.
        ///
        /// For more information, see [Email
        /// mask](https://cloud.google.com/bigquery/docs/column-data-masking-intro#masking_options).
        EmailMask,
        /// Masking expression to only show the \<i\>year\</i\> of `Date`,
        /// `DateTime` and `TimeStamp`. For example, with the
        /// year 2076:
        ///
        /// * DATE         :  2076-01-01
        /// * DATETIME     :  2076-01-01T00:00:00
        /// * TIMESTAMP    :  2076-01-01 00:00:00 UTC
        ///
        /// Truncation occurs according to the UTC time zone. To change this, adjust
        /// the default time zone using the `time_zone` system variable.
        /// For more information, see [System variables
        /// reference](https://cloud.google.com/bigquery/docs/reference/system-variables).
        DateYearMask,
        /// Masking expression that uses hashing to mask column data.
        /// It differs from SHA256 in that a unique random value is generated for
        /// each query and is added to the hash input, resulting in the hash / masked
        /// result to be different for each query. Hence the name "random hash".
        RandomHash,
        /// If set, the enum was initialized with an unknown value.
        ///
        /// Applications can examine the value using [PredefinedExpression::value] or
        /// [PredefinedExpression::name].
        UnknownValue(predefined_expression::UnknownValue),
    }

    #[doc(hidden)]
    pub mod predefined_expression {
        #[allow(unused_imports)]
        use super::*;
        #[derive(Clone, Debug, PartialEq)]
        pub struct UnknownValue(pub(crate) wkt::internal::UnknownEnumValue);
    }

    impl PredefinedExpression {
        /// Gets the enum value.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the string representation of enums.
        pub fn value(&self) -> std::option::Option<i32> {
            match self {
                Self::Unspecified => std::option::Option::Some(0),
                Self::Sha256 => std::option::Option::Some(1),
                Self::AlwaysNull => std::option::Option::Some(2),
                Self::DefaultMaskingValue => std::option::Option::Some(3),
                Self::LastFourCharacters => std::option::Option::Some(4),
                Self::FirstFourCharacters => std::option::Option::Some(5),
                Self::EmailMask => std::option::Option::Some(6),
                Self::DateYearMask => std::option::Option::Some(7),
                Self::RandomHash => std::option::Option::Some(8),
                Self::UnknownValue(u) => u.0.value(),
            }
        }

        /// Gets the enum value as a string.
        ///
        /// Returns `None` if the enum contains an unknown value deserialized from
        /// the integer representation of enums.
        pub fn name(&self) -> std::option::Option<&str> {
            match self {
                Self::Unspecified => std::option::Option::Some("PREDEFINED_EXPRESSION_UNSPECIFIED"),
                Self::Sha256 => std::option::Option::Some("SHA256"),
                Self::AlwaysNull => std::option::Option::Some("ALWAYS_NULL"),
                Self::DefaultMaskingValue => std::option::Option::Some("DEFAULT_MASKING_VALUE"),
                Self::LastFourCharacters => std::option::Option::Some("LAST_FOUR_CHARACTERS"),
                Self::FirstFourCharacters => std::option::Option::Some("FIRST_FOUR_CHARACTERS"),
                Self::EmailMask => std::option::Option::Some("EMAIL_MASK"),
                Self::DateYearMask => std::option::Option::Some("DATE_YEAR_MASK"),
                Self::RandomHash => std::option::Option::Some("RANDOM_HASH"),
                Self::UnknownValue(u) => u.0.name(),
            }
        }
    }

    impl std::default::Default for PredefinedExpression {
        fn default() -> Self {
            use std::convert::From;
            Self::from(0)
        }
    }

    impl std::fmt::Display for PredefinedExpression {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
            wkt::internal::display_enum(f, self.name(), self.value())
        }
    }

    impl std::convert::From<i32> for PredefinedExpression {
        fn from(value: i32) -> Self {
            match value {
                0 => Self::Unspecified,
                1 => Self::Sha256,
                2 => Self::AlwaysNull,
                3 => Self::DefaultMaskingValue,
                4 => Self::LastFourCharacters,
                5 => Self::FirstFourCharacters,
                6 => Self::EmailMask,
                7 => Self::DateYearMask,
                8 => Self::RandomHash,
                _ => Self::UnknownValue(predefined_expression::UnknownValue(
                    wkt::internal::UnknownEnumValue::Integer(value),
                )),
            }
        }
    }

    impl std::convert::From<&str> for PredefinedExpression {
        fn from(value: &str) -> Self {
            use std::string::ToString;
            match value {
                "PREDEFINED_EXPRESSION_UNSPECIFIED" => Self::Unspecified,
                "SHA256" => Self::Sha256,
                "ALWAYS_NULL" => Self::AlwaysNull,
                "DEFAULT_MASKING_VALUE" => Self::DefaultMaskingValue,
                "LAST_FOUR_CHARACTERS" => Self::LastFourCharacters,
                "FIRST_FOUR_CHARACTERS" => Self::FirstFourCharacters,
                "EMAIL_MASK" => Self::EmailMask,
                "DATE_YEAR_MASK" => Self::DateYearMask,
                "RANDOM_HASH" => Self::RandomHash,
                _ => Self::UnknownValue(predefined_expression::UnknownValue(
                    wkt::internal::UnknownEnumValue::String(value.to_string()),
                )),
            }
        }
    }

    impl serde::ser::Serialize for PredefinedExpression {
        fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
        where
            S: serde::Serializer,
        {
            match self {
                Self::Unspecified => serializer.serialize_i32(0),
                Self::Sha256 => serializer.serialize_i32(1),
                Self::AlwaysNull => serializer.serialize_i32(2),
                Self::DefaultMaskingValue => serializer.serialize_i32(3),
                Self::LastFourCharacters => serializer.serialize_i32(4),
                Self::FirstFourCharacters => serializer.serialize_i32(5),
                Self::EmailMask => serializer.serialize_i32(6),
                Self::DateYearMask => serializer.serialize_i32(7),
                Self::RandomHash => serializer.serialize_i32(8),
                Self::UnknownValue(u) => u.0.serialize(serializer),
            }
        }
    }

    impl<'de> serde::de::Deserialize<'de> for PredefinedExpression {
        fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
        where
            D: serde::Deserializer<'de>,
        {
            deserializer.deserialize_any(wkt::internal::EnumVisitor::<PredefinedExpression>::new(
                ".google.cloud.bigquery.datapolicies.v2.DataMaskingPolicy.PredefinedExpression",
            ))
        }
    }

    /// A masking expression to bind to the data masking rule.
    #[derive(Clone, Debug, PartialEq)]
    #[non_exhaustive]
    pub enum MaskingExpression {
        /// Optional. A predefined masking expression.
        PredefinedExpression(crate::model::data_masking_policy::PredefinedExpression),
        /// Optional. The name of the BigQuery routine that contains the custom
        /// masking routine, in the format of
        /// `projects/{project_number}/datasets/{dataset_id}/routines/{routine_id}`.
        Routine(std::string::String),
    }
}
